package com.acwing.partition2;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author `RKC`
 * @date 2021/12/3 10:23
 */
public class AC125耍杂技的牛 {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int[][] cattle = new int[n][2];
        for (int i = 0; i < n; i++) {
            s = reader.readLine().split(" ");
            cattle[i][0] = Integer.parseInt(s[0]);
            cattle[i][1] = Integer.parseInt(s[1]);
        }
        writer.write(greedy(cattle) + "\n");
        writer.flush();
    }

    private static long greedy(int[][] cattle) {
        //尽量将又强壮又重的牛放在下面
        Arrays.sort(cattle, Comparator.comparingInt(o -> o[0] + o[1]));
        long answer = -0x3f3f3f3f, sum = 0;
        for (int[] item : cattle) {
            answer = Math.max(answer, sum - item[1]);
            sum += item[0];
        }
        return answer;
    }
}
